package com.mp3s.backtest;

import java.util.ArrayList;
import java.util.List;

import com.mp3s.backtest.utils.schedule;
import com.mp3s.interface3.BSData;
import com.mp3s.interface3.IBT;
import com.mp3s.interface3.IBackTest;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.StrUtil;


public class backtest implements IBackTest{

	private String version="backtest-0.0.1";

    private schedule sc  = new schedule();

	//BS 规则
	private List<BSData> bsds = new ArrayList<>();

	public void parseBSCfg(String cfg,int lineId){

		List<String> ids = StrUtil.split(cfg, ',');
		if(ids.size() < 5){
			System.out.println("strategy cfg error");
			return;
		}
		BSData bsd =new BSData();
		int idx = 0;
		bsd.setOpen(Convert.toFloat(ids.get(idx)));
		idx++;
		bsd.setClose(Convert.toFloat(ids.get(idx)));
		idx++;
		bsd.setHigh(Convert.toFloat(ids.get(idx)));
		idx++;
		bsd.setLow(Convert.toFloat(ids.get(idx)));
		idx++;
		bsd.setVolume(Convert.toFloat(ids.get(idx)));

		System.out.println("strategyA:"+bsd.toString());
		bsds.add(bsd);
	}

	
    public String TodyDate(){

        // 获得当前日期
        DateTime dt = DateTime.now();
        int n1  = dt.getField(DateField.YEAR);
        int n2  = dt.getField(DateField.MONTH)+1;
        String n2s=""+n2;
        int n3  = dt.getField(DateField.DAY_OF_MONTH);
        String n3s=""+n3;
        if(n2<10){
            n2s="0"+n2;
        }
        if(n3<10){
            n3s="0"+n3;
        }
        String date = n1+"-"+n2s+"-"+n3s;
        return date;
    }

    // 上一个交易日
    public String LastDate(){
        return "";
    }


	@Override
    public String version() {
		System.out.println(version);
		return version;
	}

	@Override
	public void init(IBT ibt) {
		//加载BT历史
		sc.init("BACK-TEST", "", ibt);
	}

	
	@Override
	public void init() {
		// TODO Auto-generated method stub
		// throw new UnsupportedOperationException("Unimplemented method 'init'");
	}
	
	@Override
	public void start() {
		// TODO Auto-generated method stub
		// throw new UnsupportedOperationException("Unimplemented method 'start'");
		// 开启定时任务，判断BS时机
		sc.start();

	}

	@Override
	public void end() {
		// TODO Auto-generated method stub
		// throw new UnsupportedOperationException("Unimplemented method 'end'");
		sc.stop();
	}



}
